<?php
class Admin_ViewlogController extends Zend_Controller_Action
{
	private $_model;
	public function init()
	{
		$this->_model = new Admin_Model_Viewlog();
		$dirfile = $this->_request->getBaseUrl() . "/application/layouts/admin";
		$dirlayout = APPLICATION_PATH . "/layouts/admin";
		$this->view->imgs = $dirfile . "/images";
		$this->view->headLink()->appendStylesheet($dirfile . '/css/style.css');
		$this->view->headLink()->appendStylesheet($dirfile . '/css/jquery-ui-1.8.18.custom.css');
		$this->view->headScript()->appendFile($dirfile . '/js/jquery-1.7.2.min.js');
		$this->view->headScript()->appendFile($dirfile . '/js/dropdown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/slidedown.js');
		$this->view->headScript()->appendFile($dirfile . '/js/checkbox.js');
		$this->view->headScript()->appendFile($dirfile . '/js/dellog.js');
		$this->view->headScript()->appendFile($dirfile . '/js/deleteAll.js');
		$option = array('layoutPath'=>$dirlayout,'layout'=>'index');
		Zend_Layout::startMvc($option);
	}
	public function indexAction()
	{
		$data = $this->_model->viewlogall();
		$paging = Zend_Paginator::factory($data);
		$paging->setItemCountPerPage(2);
		$paging->setPageRange(2);
		$current = $this->_request->getParam('page',1);
		$paging->setCurrentPageNumber($current);
		$this->view->paging = $paging;
	}
	public function getsearchAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$contents = $this->_request->getParam('text-search');
		$session = new Zend_Session_Namespace('searchlog');
		$session->content = $contents;
		$this->_forward('search');
	}
	public function searchAction()
	{
		$session = new Zend_Session_Namespace('searchlog');
		$contents = $session->content;
		$search = $this->_model->search($contents);
		$pagingsearch = Zend_Paginator::factory($search);
		$pagingsearch->setItemCountPerPage(2);
		$pagingsearch->setPageRange(3);
		$currentsearch = $this->_request->getParam('page',1);
		$pagingsearch->setCurrentPageNumber($currentsearch);
		$this->view->pagingsearch = $pagingsearch;
	}
	public function deleteAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$id=$this->_request->getParam('id');
		try{
		$delete = $this->_model->delete($id);
		echo "Delete thanh cong";
		}catch(Zend_Db_Exception $e)
		{
			echo "Loi xu ly";
		}
	}
	public function deleteallAction()
	{
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();
		$count = $this->_request->getParam('count');
		$arr = $this->_request->getParam('arr');
		foreach ($arr as $value)
		{
			//echo $value;
			$delete = $this->_model->deleteall($value);
		}
		echo $delete;
		//Zend_Debug::dump($arr,'mang');
	}
}